//
//  LXOrderSelfView.m
//  跑跑快销
//
//  Created by linxian on 14-5-8.
//  Copyright (c) 2014年 ylife. All rights reserved.
//
#define ViewHeight                      [UIScreen mainScreen].bounds.size.height
#define searchBarH                      40
#define TitleWidth 320 / 4
#define LableHeight 50
#import "LXOrderSelfView.h"

@implementation LXOrderSelfView
@synthesize oTableView, addGood, scanGood, blackBtn, blackBtnTwo, showSV, showAV, searchField, priceField, numberField, goodName, goodCode, goodNumber, commitBtn;
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self createTitleView];
        [self createTableView];
        [self createBottomBtns];
    }
    return self;
}

- (void)createTitleView
{
    int navBarY,navBarH;
    
    if (ISDEVICE7) {
        navBarY = 0;
        navBarH = 64;
    }else{
        navBarY = 20;
        navBarH = 44;
    }
    _navBarH = navBarH;
    _navBarY = navBarY;
    
    UILabel *lable1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, TitleWidth, 60)];
    lable1.text = @"名称";
    lable1.textAlignment = NSTextAlignmentCenter;
    lable1.layer.borderWidth = 0.25;
    lable1.layer.borderColor = [UIColor blackColor].CGColor;
    [self addSubview:lable1];
    
    UILabel *lable2 = [[UILabel alloc]initWithFrame:CGRectMake(TitleWidth , 0, TitleWidth, 60)];
    lable2.text = @"规格";
    lable2.textAlignment = NSTextAlignmentCenter;
    lable2.layer.borderWidth = 0.25;
    lable2.layer.borderColor = [UIColor blackColor].CGColor;
    [self addSubview:lable2];
    
    UILabel *lable3 = [[UILabel alloc]initWithFrame:CGRectMake(TitleWidth * 2, 0, TitleWidth, 60)];
    lable3.text = @"单价";
    lable3.textAlignment = NSTextAlignmentCenter;
    lable3.layer.borderWidth = 0.25;
    lable3.layer.borderColor = [UIColor blackColor].CGColor;
    [self addSubview:lable3];
    
    UILabel *lable4 = [[UILabel alloc]initWithFrame:CGRectMake(TitleWidth * 3, 0, TitleWidth, 60)];
    lable4.text = @"条码";
    lable4.textAlignment = NSTextAlignmentCenter;
    lable4.layer.borderWidth = 0.25;
    lable4.layer.borderColor = [UIColor blackColor].CGColor;
    [self addSubview:lable4];
}

- (void)createTableView
{
    oTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 60, 320, PHONESIZEHEIGHT - STARTY - LableHeight - 60)];
    NSLog(@"%f",self.frame.size.height);
    [oTableView registerClass:[LXFormCell class] forCellReuseIdentifier:@"LXFormCell"];
    [oTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    oTableView.showsVerticalScrollIndicator = NO;
    [oTableView setBounces:NO];
    [self addSubview:oTableView];
}

-(void)createBottomBtns
{
    addGood = [[UIButton alloc] initWithFrame:CGRectMake(0, PHONESIZEHEIGHT - STARTY - LableHeight, 320, LableHeight)];
    addGood.backgroundColor = [UIColor redColor];
    [addGood setTitle:@"       添加商品规格" forState:UIControlStateNormal];
    addGood.tag = 4;
    [self addSubview:addGood];
    UIImageView *addGoodImg = [[UIImageView alloc] initWithFrame:CGRectMake(90, LableHeight/4.0, LableHeight/2.0, LableHeight/2.0)];
    addGoodImg.backgroundColor = [UIColor lightGrayColor];
    [addGood addSubview:addGoodImg];
    
    ///
//    scanGood = [[UIButton alloc] initWithFrame:CGRectMake(0, PHONESIZEHEIGHT - STARTY - LableHeight, 320, LableHeight)];
//    scanGood.backgroundColor = [UIColor brownColor];
//    [scanGood setTitle:@"扫码下单" forState:UIControlStateNormal];
//    scanGood.tag = 5;
//    [self addSubview:scanGood];
//    UIImageView *scanGoodImg = [[UIImageView alloc] initWithFrame:CGRectMake(LableHeight/4.0, LableHeight/4.0, LableHeight/2.0, LableHeight/2.0)];
//    scanGoodImg.backgroundColor = [UIColor lightGrayColor];
//    [scanGood addSubview:scanGoodImg];
}

- (void)showSearchView
{
    showSV = YES;
    if (blackBtn) {
        blackBtn.hidden = NO;
    } else {
        [self createSearchView];
    }
}

- (void)hiddenSearchView
{
    showSV = NO;
    blackBtn.hidden = YES;
    [searchField resignFirstResponder];
}

- (void)createSearchView
{
    //加黑色
    blackBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, _navBarY+20, 320, self.window.frame.size.height-_navBarY)];
    blackBtn.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.35];
    [blackBtn addTarget:self action:@selector(hiddenSearchView) forControlEvents:UIControlEventTouchUpInside];
    [self.window addSubview:blackBtn];
    
    // 搜索框
    searchField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 320, searchBarH)];
    searchField.borderStyle = UITextBorderStyleRoundedRect;
    searchField.backgroundColor = [UIColor whiteColor];
    [blackBtn addSubview:searchField];
    
    //设置文本左边图片
    UIImageView *image0 =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pass.png"]];
    image0.frame = CGRectMake(0, 0, searchField.frame.size.height, searchField.frame.size.height);
    searchField.leftView = image0;
    searchField.leftViewMode = UITextFieldViewModeAlways;
    
}

- (void)showAddView
{
    showAV = YES;
    if (blackBtnTwo) {
        blackBtnTwo.hidden = NO;
    } else {
        [self createAddView];
    }
}

- (void)hiddenAddView
{
    showAV = NO;
    blackBtnTwo.hidden = YES;
    [priceField resignFirstResponder];
    [numberField resignFirstResponder];
}


- (void)createAddView
{
    //加黑色
    blackBtnTwo = [[UIButton alloc] initWithFrame:CGRectMake(0, _navBarY+20, 320, self.window.frame.size.height-_navBarY)];
    blackBtnTwo.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.35];
    //[blackBtnTwo addTarget:self action:@selector(hiddenAddView) forControlEvents:UIControlEventTouchUpInside];
    [self.window addSubview:blackBtnTwo];
    
    // 下单视图
    _addView = [[UIView alloc] initWithFrame:CGRectMake(0, ViewHeight - 280, 320, 280)];
    _addView.backgroundColor = [UIColor lightGrayColor];
    [blackBtnTwo addSubview:_addView];
    
    // 商品名
    goodName = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 260, searchBarH)];
    goodName.backgroundColor = [UIColor blueColor];
    [_addView addSubview:goodName];
    
    // 取消按钮
    UIButton *quxiao = [[UIButton alloc] initWithFrame:CGRectMake(270, 10, 40, 40)];
    quxiao.backgroundColor = [UIColor brownColor];
    [quxiao addTarget:self action:@selector(hiddenAddView) forControlEvents:UIControlEventTouchUpInside];
    [_addView addSubview:quxiao];
    
    // 条码标签
    goodCode = [[UILabel alloc] initWithFrame:CGRectMake(10, 10+(searchBarH+10), 150, 40)];
    goodCode.backgroundColor = [UIColor yellowColor];
    goodCode.text = @"条码：";
    [_addView addSubview:goodCode];
    
    // 数量标签
    goodNumber = [[UILabel alloc] initWithFrame:CGRectMake(200, 10+(searchBarH+10), 110, 40)];
    goodNumber.backgroundColor = [UIColor yellowColor];
    goodNumber.text = @"数量：";
    [_addView addSubview:goodNumber];
    
    // 单价框
    priceField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10+(searchBarH+10)*2, 300, searchBarH)];
    priceField.borderStyle = UITextBorderStyleRoundedRect;
    priceField.backgroundColor = [UIColor whiteColor];
    [_addView addSubview:priceField];
    
    //单价左边图片
    UIImageView *image0 =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pass.png"]];
    image0.frame = CGRectMake(11, 11, priceField.frame.size.height/2.0, priceField.frame.size.height/2.0);
    image0.backgroundColor = [UIColor lightGrayColor];
    priceField.leftView = image0;
    priceField.leftViewMode = UITextFieldViewModeAlways;
    
    // 数量框
    numberField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10+(searchBarH+10)*3, 300, searchBarH)];
    numberField.borderStyle = UITextBorderStyleRoundedRect;
    numberField.backgroundColor = [UIColor whiteColor];
    [_addView addSubview:numberField];
    
    //数量左边图片
    UIImageView *image1 =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pass.png"]];
    image1.frame = CGRectMake(11, 11, numberField.frame.size.height/2.0, numberField.frame.size.height/2.0);
    image1.backgroundColor = [UIColor lightGrayColor];
    numberField.leftView = image1;
    numberField.leftViewMode = UITextFieldViewModeAlways;
    
    // 提交按钮
    commitBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 10+(searchBarH+10)*4, 300, 40)];
    commitBtn.backgroundColor = [UIColor brownColor];
    [commitBtn setTitle:@"加入订单" forState:UIControlStateNormal];
    [_addView addSubview:commitBtn];
}

@end
